// pages/image1/index.js
var t = getApp(),
  c = t.requirejs("api/index"),
  a = t.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    route: "image",
    menu: t.tabBar,
    menu_show: false,
    loaded: false,
    show: false,
    list: [],
    page: 1
  },
  //底部导航跳转
  menu_url: function (k) {
    a.menu_url(k, 2);
  },
  onLoad: function (e) {

    if (e != null && e != undefined) {
      this.setData({
        tabbar_index: e.tabbar_index ? e.tabbar_index : -1
      });
    }

    a.setting();
    console.log(e)
    this.setData({
      menu: getApp().tabBar,
    })

    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: getApp().tabBar.IsDiDis ? getApp().tabBar.IsDiDis : false,
      })
    }
    
    if (e.id){
      this.setData({
        group_id: e.id
      })
      this.getlist()
    }else{
      a.error('未获取相册类别')
    }
    
  },
  /**
     * 获取图片列表信息
     */
  getlist: function () {
    var that = this,
      ident = '',
      group_id = that.data.group_id,
      page = that.data.page;
    c.ImageInfo(ident, page, group_id, that, function (t) {
      that.setData(t)
    })
  },
  
  /**
    * 图片预览
    */
  previewImage:function(e){
    var that = this,
    urls=[];
    that.data.list.forEach(function(t,k){
      urls[k] = t.img_cover
    })
    wx.previewImage({
      current: a.pdata(e).url, // 当前显示图片的http链接
      urls: urls// 需要预览的图片http链接列表
    })
  },
 
  /**
    * 下拉刷新
    */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded:false
    })
    this.getlist()
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.getlist()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },
  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  //
  // }
})